<template>
  <div class="users_list">
    <!-- <el-checkbox-group v-model="dataForm[scriptItem.text]" @change="checkBoxGrounpChange"> -->
      <el-select v-model="dataForm[scriptItem.text]" @change="selectChange" clearable  :placeholder="$t('placeholder.s')">
        <el-option
          v-for="item in scriptItem[scriptItem.toSelectListField]"
          :key="item[scriptItem.userLable]"
          :label="item[scriptItem.userLable]"
          :value="item[scriptItem.userLable]">
          <!-- <el-checkbox @click.native="(e) => {e.preventDefault()}" :label="item[scriptItem.lable]"></el-checkbox> -->
        </el-option>
      </el-select>
    <!-- </el-checkbox-group> -->
  </div>
</template>
<script>
import mixinTypeViewModule from '@/mixins/script-type-view-module'
export default {
  mixins: [mixinTypeViewModule],
  data () {
    return {
    }
  },
  computed: {
    datasetFieldList () {
      return this.scriptItem[this.scriptItem.toSelectListField]
    }
  },
  created () {
    this.getToSelectListFieldList()
  },
  methods: {
    selectChange () {
      this.$forceUpdate()
    },
    checkBoxGrounpChange (e) {
      this.dataForm[this.scriptItem.text] = e
    },
    getToSelectListFieldList () {
      let id = this.$store.state.bot.id
      let type = this.$store.state.bot.type
      this.scriptItem[this.scriptItem.toSelectListField] = []
      if (!id) {
        return
      }
      const params = {}
      type === 'dataset' && (params['datasetId'] = id)
      type === 'widget' && (params['gadgetId'] = id)
      this.$interface.reports.getFieldsListApi(params)
        .then(({ data: res }) => {
          if (res.code !== 0) {
            this.scriptItem[this.scriptItem.toSelectListField] = []
            return false
          }
          let arr = []
          res.data.forEach(item => {
            if (item.type === 'user') {
              arr.push({
                [this.scriptItem.userValue]: item.name,
                [this.scriptItem.userLable]: item.name,
                type: item.type
              })
            }
          })
          this.scriptItem[this.scriptItem.toSelectListField] = arr
          // this.initDefUser()
        }).catch(() => {
          this.scriptItem[this.scriptItem.toSelectListField] = []
        })
    }
  }
}
</script>
<style lang="scss">
.users_list{
  .el-select{
    width: 100%;
    .el-input__inner{
      border: 0;
    }
  }
}
</style>
